﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 必须不为null, 示例:
/// <code>
/// [VNotNull]
/// public ExtInfo Ext { get; set; }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class VNotNullAttribute(string errorMessage = null) : Attribute, IValidateAction
{
    /// <summary>
    /// 错误提示
    /// </summary>
    public string ErrorMessage { get; set; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateExtensions.MustNotNullInternal(ctx, ErrorMessage);
    }
}
